package cc.vicp.djx314.starfood.util.impls;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import cc.vicp.djx314.starfood.util.DealResult;

public class DealResultImpl implements DealResult {
	@Override
	public Map<String, String> errorsToMap(BindingResult result) {
		List<FieldError> errors = result.getFieldErrors();
		Map<String, String> errorsMap = new HashMap<String, String>();
		for (FieldError error : errors) {
			errorsMap.put(error.getField(), error.getDefaultMessage());
		}
		return errorsMap;
	}
}